<template>
	<view class="ayi-page">
		<navigation :isBack="true" title="规则" titleTintColor="#fff">
			<text slot="back" class="iconfont">&#xe63d;</text>
			<view slot="string">
				<picker @change="bindPickerChange" :value="index" :range="array">
					<text class="uni-input">{{ array[index] }}</text>
				</picker>
			</view>
		</navigation>
		<view><rich-text type="text" :nodes="ruleInfo.statement"></rich-text></view>
		<view class="padding"><parser :tag-style="tagStyle" img-mode="widthFix" :html="ruleInfo.content"></parser></view>
		<Tabbar :indexpage="-1"></Tabbar>
	</view>
</template>

<script>
import { Tools, Config, URL, Net, VueTools } from '@/common/tools.js';
import navigation from '@/components/navigation.vue';
import Tabbar from '@/components/tabbar.vue';
import parser from '@/components/parser/index';
export default {
	components: { Tabbar, navigation, parser },
	data() {
		return {
			array: [''], //彩种类型的数据
			index: 0, //选中的数组下标
			lotDataArr: [], //所有菜单的数据
			lotCode: '', //选中的code值
			ruleInfo: { content: '', notes_title: '', statement: '' }, //规则的数据
			tagStyle: {
				img: '100%'
			}
		};
	},
	onLoad() {
		this.getArray();
	},
	methods: {
		/**
		 * 获取彩种的下标数据
		 */
		getArray() {
			let tempData = VueTools.getStorageSync(Config.ALL_LOT_STORE_KEY);
			let tempV = [];
			if (!Tools.isEmpty(tempData.lots) && tempData.lots.length > 0) {
				for (let i = 0; i < tempData.lots.length; i++) {
					tempV[i] = tempData.lots[i].name;
				}
				this.lotDataArr = tempData.lots;
				this.array = tempV;
				this.ruleDate(tempData.lots[0]['key']);
			} else {
				this.lotDataArr = [];
				this.array = [];
				this.lotCode = '';
			}
		},
		/**
		 * 选择查看的类别
		 */
		bindPickerChange(e) {
			this.index = e.target.value;
			this.lotCode = this.lotDataArr[this.index].key;
			this.ruleDate(this.lotCode);
		},
		/**
		 * 获取规则的数据
		 */
		ruleDate(toplotcode = 'pks') {
			let that = this;
			Net.ayiHttp(
				URL.USER_GAMRULE,
				'{"toplotcode":"' + toplotcode + '"}',
				function(res) {
					if (res.code == Config.SUCCESS_CODE) {
						//成功的逻辑
						let data = Tools.aesDecodeToJson(res.data);
						that.ruleInfo = data.artinfo;
						console.log('获取规则的数据', that.ruleInfo);
					} else if (res.code == Config.FAIL_CODE) {
						VueTools.toastNo(res.message);
					} else if (res.code == Config.LOGIN_CODE) {
						uni.navigateTo({
							url: '/pages/my/login/login'
						});
					}
				},
				function(err) {
					console.log('error:', err);
				}
			);
		}
	},
	onUnload() {}
};
</script>

<style lang="scss">
.padding {
	padding: 20rpx;
}
</style>
